using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Entity : MonoBehaviour {

    //This file contain the variables and functions common to all living entities of the game
    // (hero, minions and bosses...)

    protected CharacterController m_controller;
    protected Animator m_anim;
    protected Vector3 m_moveDirection;

    [SerializeField]
    Rigidbody[] m_ragdollBones;

    [SerializeField]
    protected Hit m_hit;

    [SerializeField]
    protected int m_life = 1;

    [SerializeField]
    protected int m_maxLife;

    [SerializeField]
    protected int m_resistance;

    [SerializeField]
    protected int m_strenght = 1;

    protected int m_team;


    protected bool m_active;

    public int Strength {  get { return this.m_strenght; } }
    public Hit Hit {  get { return this.m_hit; } }
    public int Team {  get { return m_team; } }
    public bool Activated { get { return m_active; }  set{m_active = value;} }

    //Initiatilization of components
    protected virtual void Start()
    {
        m_controller = GetComponent<CharacterController>();
        m_anim = GetComponent<Animator>();
        m_active = true;
        m_hit.Owner = this;

        for (int i = 0; i < m_ragdollBones.Length; i++)
            m_ragdollBones[i].isKinematic = true;
    }

    //Taking Damages
    public virtual void takeDamages(int damages)
    {
        if (m_life == 0)
            return;

        m_life -= (damages - m_resistance);

        if(m_life <=0)
        {
            m_life = 0;
            defeated();
        }

    }

    //These utilisations are different in each entitie, so they are virtual
    protected virtual void attack() {}
    protected virtual void defeated()
    {
        m_controller.enabled = false;
        m_anim.enabled = false;
        m_active = false;

        for (int i = 0; i < m_ragdollBones.Length; i++)
            m_ragdollBones[i].isKinematic = false;
    }
    protected virtual void initAnimator(){}
    protected virtual void linkingAnimator(){}


}
